/**
 * gwt-validator 
 *
 * Copyright (C) 2006  Nikolaus Rumm, Christian Simonutti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package gwt.validator.client.util;

import gwt.validator.client.ValidationScope;
import gwt.validator.client.check.Check;
import gwt.validator.client.check.MandatoryCheck;

import java.util.Iterator;

/**
 * Utility class that applies the given css style to all widgets that are
 * covered by a MandatoryCheck.
 * 
 * The style will be applied to the label. If there's no label associated with
 * the mandatory widget then nothing will happen.
 * 
 * @author <a href="mailto:nikolaus.rumm@gmail.com">Nikolaus Rumm</a>
 * 
 */
public class MandatoryFieldHighlighter {

	/**
	 * Highlights all labels that are associated with a widget whose data in
	 * constrained by a MandatoryCheck.
	 * 
	 * @param aScopes
	 *            The scopes that will be searched for MandatoryChecks
	 * @param aStyle
	 *            The style to apply
	 */
	public static void execute(ValidationScope[] aScopes, String aStyle) {
		for (int i = 0; i < aScopes.length; i++) {
			Iterator it = aScopes[i].getChecks().iterator();
			while (it.hasNext()) {
				Check currentCheck = (Check) it.next();

				if (currentCheck instanceof MandatoryCheck) {
					MandatoryCheck check = (MandatoryCheck) currentCheck;
					if (check.getPropertyNameLabel() != null) {
						check.getPropertyNameLabel().setStyleName(aStyle);
					}
				}
			}
		}
	}
}
